package com.yxy.springcloud.framework.unionauth.controller;

import com.yxy.springcloud.framework.common.base.BusinessException;
import com.yxy.springcloud.framework.common.base.Pagingable;
import com.yxy.springcloud.framework.common.base.RestResponse;
import com.yxy.springcloud.framework.unionauth.DTO.*;
import com.yxy.springcloud.framework.unionauth.model.AppDataDic;
import com.yxy.springcloud.framework.unionauth.model.AppSystemSetting;
import com.yxy.springcloud.framework.unionauth.service.AppSystemSettingService;
import com.yxy.springcloud.framework.unionauth.utils.CheckAppPermission;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yuxiaoyang
 * app 系统参数设置相关接口
 */
@RestController
@RequestMapping("/app-system-setting")
public class AppSystemSettingController {
  @Resource
  private AppSystemSettingService functionService;

  @Pagingable
  @PostMapping("/list")
  public RestResponse getList(@RequestBody AppSystemSettingQueryDto query) {
    RestResponse restResponse = new RestResponse(200, "success");
    restResponse.setContent(functionService.getList(query));
    return restResponse;
  }

  @PostMapping("/createOrUpdate")
  public RestResponse createOrUpdate(@RequestBody AppSystemSetting inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "success");
    restResponse.setContent(functionService.createOrUpdate(inputDto));
    return restResponse;
  }

  @DeleteMapping("/{id}")
  public RestResponse delete(@PathVariable("id") long id) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    functionService.delete(id);
    return restResponse;
  }

  // 根据appCode以及paramKey获取参数值
  // @CheckAppPermission需配合TokenCheckUtil.noAuthUrls一起使用
  @CheckAppPermission
  @PostMapping("/getParamValue")
  public RestResponse getParamValue(@RequestBody GetParamValueQueryDTO inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(functionService.getParamValue(inputDto));
    return restResponse;
  }
}
